package com.chexiehui.jc.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aries.ui.view.radius.RadiusTextView;
import com.chexiehui.jc.R;
import com.chexiehui.jc.entity.BrandInfo;
import com.chexiehui.jc.utils.GlideUtil;
import com.lxj.xpopup.impl.PartShadowPopupView;
import com.lxj.xpopup.util.KeyboardUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class CustomChooseBrandPopup extends PartShadowPopupView {


    @BindView(R.id.iv_brand_icon)
    ImageView ivBrandIcon;
    @BindView(R.id.tv_brand_name)
    TextView tvBrandName;
    @BindView(R.id.iv_delete_brand)
    ImageView ivDeleteBrand;
    @BindView(R.id.rl_model_container)
    RelativeLayout rlModelContainer;
    @BindView(R.id.rtv_choose)
    RadiusTextView rtvChoose;
    private Unbinder mUnBinder;
    private BrandInfo chooseBrand;
    private ICustomChooseBrandPopupListener listener;

    public CustomChooseBrandPopup(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.layput_custom_choose_brand_popup;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        mUnBinder = ButterKnife.bind(this);
    }

    public void initBrandModel(BrandInfo brandInfo) {
        this.chooseBrand = brandInfo;
    }

    //完全可见执行
    @Override
    protected void onShow() {
        super.onShow();
        setBrandInfo();
    }

    public void setListener(ICustomChooseBrandPopupListener listener) {
        this.listener = listener;
    }

    private void setBrandInfo() {
        if (chooseBrand == null) {
            rlModelContainer.setVisibility(GONE);
        } else {
            rlModelContainer.setVisibility(VISIBLE);
            GlideUtil.loadImageViewCrop(getContext(), chooseBrand.getImg(), ivBrandIcon,  R.drawable.shape_square, R.drawable.shape_square);
            tvBrandName.setText(chooseBrand.getName());
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mUnBinder != null) {
            mUnBinder.unbind();
        }
    }

    @OnClick({R.id.iv_delete_brand, R.id.rtv_choose})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_delete_brand:
                dismiss();
                if(listener != null){
                    listener.onRemoveBrand();
                }
                break;
            case R.id.rtv_choose:
                dismiss();
                if(listener != null){
                    listener.onChooseBrand();
                }
                break;
        }
    }

    public interface ICustomChooseBrandPopupListener{
        void onRemoveBrand();
        void onChooseBrand();
    }

}
